<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性</title>
</head>
<body>
    <div id="app">
        {{reverseMsg}}
        <p>{{fullName}}</p>
        <button @click="handleClick">点击改变</button>
    </div>
    <script src="vue.js"></script>
    <script>
        new Vue({
            el:'#app',
            data:{
                msg:'hello world',
                firstName:'小',
                lastName:'太阳'
            },
            methods:{
                handleClick(){
                    this.msg="你是年少的欢喜";
                    this.lastName='胖子';
                }
            },
            computed:{
                // computed默认只有getter方法
                // 计算属性最大的有点：产生缓存 如果数据没有发生变化，直接从缓存中取
                reverseMsg:function(){
                    return this.msg.split('').reverse().join('')
                },
                fullName:function(){
                    return this.firstName+this.lastName;
                }
            }
        })
    </script>
</body>
</html>